package org.jcb.view;

import org.jcb.ChinoisActivity;
import org.jcb.ChoixArrayAdapter;
import org.jcb.R;
import org.jcb.dao.data.GlobalDAO;
import org.jcb.model.ButtonQuizz;
import org.jcb.model.User;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;

public class ButtonChoixQuizzView extends LinearLayout implements OnClickListener {
	///Button[] buttonChoice = new Button[15] ;
	ChinoisActivity chinoisActivity ;
	ButtonQuizz[] buttonQuizz ;
	GridView gridView;
	private User user ;
	Integer idTypeQuizz ;
	

	public ButtonChoixQuizzView(Context context,ChinoisActivity chinoisActivity, User user, Integer idTypeQuizz)  {
		super(context);
		this.chinoisActivity = chinoisActivity ;
		this.user = user ;
		this.idTypeQuizz = idTypeQuizz ;
		LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View viewChoiceQuizz = layoutInflater.inflate(R.layout.menu_quizz_pinyin,this);
		Log.i("MenuQuizzPinyinView", "avt getChoixPinyin"  );
		buttonQuizz = ChinoisActivity.globalDAO.getChoixPinyin(idTypeQuizz,user);
		Log.i("MenuQuizzPinyinView", "apres getChoixPinyin"  );
		gridView = (GridView) findViewById(R.id.gridView);
		ChoixArrayAdapter adapter = new ChoixArrayAdapter(context,R.layout.cellmenu, buttonQuizz,this);		
		gridView.setAdapter(adapter);
			
	}

	public void launchQuizzPinyin() {
    	
	}

	private int getIdButton(Button b) {
		String txt = b.getText().toString().replace("*", "") ;
		txt = txt.replace("\n", "");
		Log.d("TAG", "btnnnnnnnn clicked" + txt);
		return Integer.parseInt(txt) ;
	}
	
	public void onClick(View v) {
		Button b = (Button) v ;
		chinoisActivity.launchQuizzPinyin(idTypeQuizz, getIdButton(b)) ;
	}
	
	
	
}
